//先把该文件定义成一个模块
define(['template','req','jquery'],(template,req)=>{
    class Header{
        constructor(){
            this.init()
            this.count=0
           
        }
        init(){
         $('header').load('/html/header.html',()=>{
              this.getNavData()
         })
        }
        //获取导航栏数据
        getNavData(){
           req.getHeaderNav()
            .then(res=>{
                // console.log(res)
                const{ code , data:{list}} = res
                //截取数据
                const arr=list.splice(1,5)
                if(code===200){
                    this.renderNav(arr)
                }
            })
        }
        //渲染导航栏
        renderNav(list){
            // console.log(list)
            const html=template('navTemplate',{list})
            $('.n-right ul').html(html)
            this.changeCount()
        }
        changeCount(){
            this.count=0
           let prodList=localStorage.getItem('prodList')
            if(prodList){
                prodList=JSON.parse(prodList)
                prodList.forEach(item => {
                    this.count += item.checked ? item.count : 0
                })
            }
            $('font').text(this.count)
            $('.gwc span1').text(this.count)
        }
    }
    return new Header()
})